This article introduces the content of PHP built-in functions using the compact (), has a certain reference value, now share to everyone, the need for friends can refer to
Today, when using tpshop, we found a PHP built-in function called Compact (), which creates an array of variables with the arguments. If an array exists in the parameter, the value of the variable in the array is also fetched.
This can reduce the amount of point code. Like what
/** * Get shopping cart price details
. getElementsByTagName ("item ");Node item = itemList. item (0 );Node cloneItem = item. cloneNode (true );// If the shopping cart is empty, a new shopping cart is structured.If (isCartEmpty ()){MyCart. emptyCart ();}// If the item is not in the shopping cart, insert it into the item and calculate the total amount.If (! IsItemExist (item, myCart )){// Obtain the root element of myCart and add the copied item node to the endElement cartRoot = myCart. getDocumentElement ();Node cartNode = cartRoot.
XMLDocumentXMLDocument itemAdded = parseString (stringItem); // retrieve the item node, and copy it to NodeList itemList = itemAdded. getElementsByTagName ("item"); Node item = itemList. item (0); Node cloneItem = item. cloneNode (true); // if the shopping cart is empty, a new shopping cart, if (isCartEmpty () {myCart, is constructed. emptyCart ();} // if the item is not in the shopping cart, insert the item and calculate the total amount if (! IsItemExist (item, myCart) {// Obtain the root Ele
cartroot=mycart.getdocumentelement ();Node Cartnode=cartroot.appendchild (Cloneitem);Computetotal (); Calculate Total Amount}}3. Delete MerchandiseDelete a product, that is, the item element of the item according to the commodity codeRemoved from the root element cart of Mycart,And recalculate the total value:public void Moveitemfromcart (String id) {Remove the node set Cartlist with item and the root element cartrootNodeList
to the backElement cartroot=mycart.getdocumentelement ();Node Cartnode=cartroot.appendchild (Cloneitem);Computetotal (); Calculate Total Amount}}3. Delete MerchandiseDelete a product, that is, the item element of the item according to the commodity codeRemoved from the root element cart of Mycart,And recalculate the total value:public void Moveitemfromcart (String id) {Remove the node set Cartlist with item and the root element cartrootNodeList
Tags: model number res workaround why turn art description functionFirst, define a goods (commodity) of the models varMongoose = require ('Mongoose'); varSchema =Mongoose.
Schema; varProductschema =NewSchema ({"productId": String,"Producname": String,"Saleprice": Number,"productimage": String}); Module.exports=mongoose.model ("Good", Productschema,'Goods'); Two, in the definition of a users (user) models varMongoose = require ('Mongoose'); varUserschema =NewMongoose. Schema ({"userId": String,"U
=s9ts5t4pa0n6arieiscnkavtd6;URL-encoded shopping cart list, decoded as JSON string cartlist=%7b%2215%22%3a%7b%22num%22%3w3%2c%22shenyu%22%3a%223582%22%2c%22money%22%3a% 221.00%22%7d%2c%2213%22%3a%7b%2;cartlistoutputstring = Urldecoder.decode (cartlist, "UTF-8");//urldecod transcoding to Utf-8MD5 user name uid=d66dbvecgvijvagjvlnyvggtvfftdgugvvjquwvq after encryption;MD5 Password after encryptionUshell=d66db
"Problem description"The items in the current user's shopping cart (cartlist), Commodity (good) selected field checked = True are displayed on the order page."General Practice" (two cycles)First take the current user's shopping cart list, loop the item inside, if Item=true, add the current item to the OrderList array, and then display the orderlist array through v-if by displaying the DOM of the order list.This type of hair is clearly used in two loop
cookie is also Key-value, and value is a string, which is the JSON -formatted dataListcartitem>list=jsonutils. Jsontolist (Cookiejson,cartitem. Class);return list;}After obtaining a list of items, the controller layer implementation shows the list:Show Shopping Cart List@requestmapping("/cart") Public String Showcart (httpservletrequest request,model model){Listcartitem>showcartlist=carservice. showcartlist (Request);Model. AddAttribute ("Cartlist",
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.